home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / misc / elcheapofax.lha / append.c < prev    next >
C/C++ Source or Header  |  1993-04-19  |  1KB  |  66 lines

  1. /*
  2.  * append.c
  3.  *
  4.  * Copyright (C) 1993 by Olaf 'Rhialto' Seibert. All rights reserved.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. int
  12. main(int argc, char **argv)
  13. {
  14.     char       *outfile = "ascii.g3";
  15.     FILE       *ofp;
  16.     FILE       *ifp;
  17.     extern char    *optarg;
  18.     extern int        optind;
  19.     extern int        getopt(int, char **, char *);
  20.     int         errflg = 0;
  21.     int         c;
  22.  
  23.     while ((c = getopt(argc, argv, "ao:rv")) != -1) {
  24.     switch (c) {
  25.         /* Append ignored */
  26.     case 'o':
  27.         outfile = optarg;
  28.         break;
  29.         /* Raw ignored */
  30.         /* Verbose ignored */
  31.     case '?':
  32.         errflg++;
  33.         break;
  34.     }
  35.     }
  36.  
  37.     if (errflg || optind >= argc) {
  38.     printf(
  39. "Usage: append [-o fax-file] files\n");
  40.     exit(EXIT_FAILURE);
  41.     }
  42.  
  43.     ofp = fopen(outfile, "ab");
  44.     if (ofp == NULL) {
  45.     printf("Can't open output file %s.\n", outfile);
  46.     exit(EXIT_FAILURE);
  47.     }
  48.  
  49.     while (optind < argc) {
  50.     char        buf[4096];
  51.     int        size;
  52.  
  53.     if (ifp = fopen(argv[optind], "rb")) {
  54.         while ((size = fread(buf, 1, sizeof(buf), ifp)) > 0)
  55.         fwrite(buf, 1, size, ofp);
  56.  
  57.         fclose(ifp);
  58.     } else {
  59.         printf("Can't open input file %s.\n", argv[optind]);
  60.     }
  61.     optind++;
  62.     }
  63.  
  64.     return 0;
  65. }
  66.